package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.CustomerReturnList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.CustomerReturnListGoodsService;
import com.atguigu.jxc.service.CustomerReturnListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author 杨林
 * @create 2023-01-29 23:27 星期日
 * description:
 */
@RestController
@RequestMapping("/customerReturnListGoods")
public class CustomerReturnListGoodsController {

    @Autowired
    CustomerReturnListGoodsService customerReturnListGoodsService;

    @Autowired
    CustomerReturnListService customerReturnListService;

    /**
     * 客户退货单保存
     * @param customerReturnList
     * @param customerReturnListGoodsStr
     * @return
     */
    @PostMapping("/save")
    public ServiceVO save(CustomerReturnList customerReturnList,
                          String customerReturnListGoodsStr,
                          HttpServletRequest httpServletRequest){

        //从session中获取用户信息
        User user = (User)httpServletRequest.getSession().getAttribute("currentUser");
        Integer userId = user.getUserId();
        customerReturnList.setUserId(userId);

        return customerReturnListGoodsService.save(customerReturnList,customerReturnListGoodsStr);
    }


    /**
     * 客户退货单查询（可查询条件：退货单号、客户、退款状态）
     * @param returnNumber
     * @param customerId
     * @param state
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> list(String returnNumber,
                                   Integer customerId,
                                   Integer state,
                                   String sTime,
                                   String eTime){

        return customerReturnListService.list(returnNumber,customerId,state,sTime,eTime);
    }


    /**
     * 退货单商品信息
     * @param customerReturnListId
     * @return
     */
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer customerReturnListId){

        return customerReturnListGoodsService.goodsList(customerReturnListId);
    }

    /**
     * 删除客户退货单
     * @param customerReturnListId
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO delete(Integer customerReturnListId){

        return customerReturnListService.delete(customerReturnListId);
    }


    /**
     * 客户退货统计（可根据 商品类别、商品编码或名称 条件查询）
     * @param sTime
     * @param eTime
     * @param goodsTypeId
     * @param codeOrName
     * @return
     */
    @PostMapping("/count")
    public String count(String sTime,
                        String eTime,
                        Integer goodsTypeId,
                        String codeOrName){

        return customerReturnListService.count(sTime,eTime,goodsTypeId,codeOrName);
    }
}
